Skip to content

sdks/rust: add Rust SDK with identical examples#193

Open
motatoes wants to merge 2 commits intomainfrom
claude/implement-rust-sdk-Z9FHC
Open

sdks/rust: add Rust SDK with identical examples#193
motatoes wants to merge 2 commits intomainfrom
claude/implement-rust-sdk-Z9FHC

Conversation

@motatoes
Copy link
Copy Markdown
Contributor

Summary

Adds a Rust SDK at sdks/rust/ that mirrors the surface of the existing Python and TypeScript SDKs.

Surface

  • Sandbox::create / connect / kill / hibernate / wake / set_timeout
  • sandbox.commands().run, .start, .background, .attach, .list, .kill — WebSocket streaming uses the same multiplexed binary protocol as the other SDKs (0x00 stdin, 0x01 stdout, 0x02 stderr, 0x03 exit, 0x04 scrollback_end)
  • sandbox.files().{read, read_bytes, write, list, make_dir, remove, exists}
  • Template::{build, list, get, delete}
  • Checkpoint + preview URL CRUD on Sandbox
  • Signed download_url / upload_url

Public API matches the Python/TS SDKs idiom-by-idiom: commands is preserved as an alias for exec for parity.

Examples (1:1 ports of the existing suites)

File Mirrors # checks
examples/test_commands.rs sdks/python/examples/test_commands.py / test-commands.ts 9 sub-tests
examples/test_file_ops.rs sdks/python/examples/test_file_ops.py / test-file-ops.ts 8 sub-tests
examples/test_python_sdk.rs sdks/python/examples/test_python_sdk.py full Python template flow

Each example creates a fresh sandbox, runs the suite, and tears the sandbox down. They exit non-zero on any failed check, so they double as integration tests.

export OPENCOMPUTER_API_KEY=osb_...
export OPENCOMPUTER_API_URL=https://app.opencomputer.dev   # or self-hosted

cd sdks/rust
cargo run --example test_commands
cargo run --example test_file_ops
cargo run --example test_python_sdk

CI

New workflow .github/workflows/test-rust-sdk.yml runs on PRs touching sdks/rust/**:

  • cargo fmt --check
  • cargo clippy --all-targets -- -D warnings
  • cargo build --all-targets
  • cargo test --tests (offline smoke tests in tests/smoke.rs)

All four pass locally on rustc 1.94.

Test plan

  • cargo fmt --check clean
  • cargo clippy --all-targets -- -D warnings clean
  • cargo build --all-targets builds lib + 3 examples
  • cargo test --tests runs tests/smoke.rs (3/3 pass — builder threading, JSON round-trip)
  • After merge, run the three examples against staging with a real OPENCOMPUTER_API_KEY to confirm the live integration paths work end-to-end (this needs a backend; the offline tests only exercise local logic).

Notes for reviewers

  • This is a new public surface, so I followed the AGENTS.md rule about preserving SDK behavior — the API mirrors Python/TS rather than reshaping things to be more "Rust-y".
  • Cargo.lock is not committed (library convention); target/ is gitignored.
  • I did not port the agent / pty / shell / secret-store / usage modules in this first pass — they can land as follow-ups once we agree on the core shape. The error type and HTTP plumbing are designed to extend cleanly.

https://claude.ai/code/session_01AbHiVWdsRLggibaXK4DRHF


Generated by Claude Code

claude added 2 commits April 26, 2026 03:56
Mirrors the surface of the Python and TypeScript SDKs:

- Sandbox::create / connect / kill / hibernate / wake / set_timeout
- commands().run, .start, .background, .attach, .list, .kill (WebSocket
  streaming over the same multiplexed binary protocol used by the other
  SDKs: 0x01 stdout, 0x02 stderr, 0x03 exit, 0x04 scrollback_end,
  0x00 stdin)
- files().{read, read_bytes, write, list, make_dir, remove, exists}
- Template::{build, list, get, delete}
- Checkpoint + preview URL CRUD on Sandbox
- signed download_url / upload_url

Examples are 1:1 ports of the existing Python/TypeScript suites:
  - test_commands.rs    (9 sub-tests, mirrors test_commands.py)
  - test_file_ops.rs    (8 sub-tests, mirrors test_file_ops.py)
  - test_python_sdk.rs  (mirrors test_python_sdk.py)

Each example creates a fresh sandbox, runs the suite, and tears the
sandbox down — they double as integration tests against a real backend
once OPENCOMPUTER_API_KEY/OPENCOMPUTER_API_URL are set:

  cargo run --example test_commands
  cargo run --example test_file_ops
  cargo run --example test_python_sdk

Offline checks (run in CI):
  cargo fmt --check
  cargo clippy --all-targets -- -D warnings
  cargo build --all-targets
  cargo test --tests

A new GitHub workflow (.github/workflows/test-rust-sdk.yml) runs all
four on PRs that touch sdks/rust.
Docs
----
- New navigation group "Rust SDK" in docs/docs.json
- New reference pages: docs/reference/rust-sdk/{overview,sandbox,exec,filesystem}.mdx
  These mirror the structure of the TS/Py reference and document the
  exact public surface (SandboxOpts, RunOpts, ExecStartOpts, StreamEvent,
  EntryInfo, ProcessResult, ExecSession, etc.)
- Add Rust tabs to the existing CodeGroups in:
    docs/introduction.mdx
    docs/quickstart.mdx
    docs/sandboxes/running-commands.mdx
    docs/sandboxes/working-with-files.mdx
- Root README: drop the inline TOML hint and instead show a real Rust
  quickstart alongside the TS one.

Examples
--------
- examples/rust/ — small Cargo project that depends on the local SDK by
  path. src/main.rs mirrors examples/test.py and examples/test.ts
  line-for-line so the three feel like the same demo across languages.
  (Sits at src/main.rs because bin/ is globally gitignored.)

SDK
---
- Re-export ExecSession, ExecStartOpts, and StreamEvent from lib.rs so
  the streaming API documented in the new reference pages is actually
  reachable from outside the crate.
- Extend tests/smoke.rs to assert those types are public + matchable.
- README.md: add a streaming snippet using the now-exported types.

CI
--
- Workflow now builds examples/rust as a second cargo project and runs
  fmt-check on both. Path filters cover both sdks/rust/** and
  examples/rust/**.

All offline checks pass locally on rustc 1.94:
  cargo fmt --check (sdks/rust + examples/rust)
  cargo clippy --all-targets -- -D warnings
  cargo build --all-targets (SDK)
  cargo build (examples/rust)
  cargo test --tests (4/4 pass)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants